<script type="text/javascript">
	var $menuadd_content = $("#menuadd_content");
	$(document).ready(function () {
		var theme = 'fresh';
		$('.field_input').addClass('jqx-input');
		$('.field_input').addClass('field');
		$('.field_input').addClass('jqx-rc-all');

		var menuadd_save = $("#menuadd_save");
		var menuadd_cancel = $("#menuadd_cancel");

		var menupost_id = $("#menupost_id");
		var menupost_task = $("#menupost_task");
		var menupost_menu = $("#menupost_menu");
		var menupost_parent = $("#menupost_parent");
		var menupost_link = $("#menupost_link");

		var parent_source = {
			id : 'id',
			datatype : "json",
			url : "index.php/c_menu/menu_list",
			root : "results",
			datafields : [
				{ name : 'id' },
				{ name : 'menu' }
			],
			beforeprocessing : function(data){
				parent_source.totalrecords = data[0].TotalRows;
			}
		}
		var parent_dataAdapter = new $.jqx.dataAdapter(parent_source,{
			loadComplete: function (){
				<?php
				if(isset($dataDetail)){
				?>
					menupost_parent.find('input').val('<?php echo $dataDetail->parentmenu_name; ?>');
				<?php } ?>
			}
		});

		menuadd_save.jqxButton({ theme : theme, width : '70px', height : '18px' });
		menuadd_cancel.jqxButton({ width : '70px' , height : '18px' ,theme : theme });

		menupost_parent.jqxComboBox({
			source : parent_dataAdapter,
			theme : theme,
			width : 300,
			height : 25,
			autoDropDownHeight: true,
			displayMember : "menu",
			valueMember : "id"
		});
		/* function */
		menuadd_cancel.click(function(){
			$('#mainpanelcontent').empty();
			$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
			$('#mainpanelcontent').load('index.php/c_menu/menu_load');
		});
		menuadd_save.click(function(){
			var id = "";
			var menu = "";
			var parent = "";
			var link = "";
			var task = "";

			id = menupost_id.val();
			if(menupost_parent.jqxComboBox('getSelectedItem') !== null){
				parent = menupost_parent.jqxComboBox('getSelectedItem').value;
			}
			menu = menupost_menu.val();
			link = menupost_link.val();
			task = menupost_task.val();

			if(task == ""){
				task = "create";
			}
			$.ajax({
				type : 'POST',
				url : 'index.php/c_menu/menu_save',
				data : {
					id : id,
					parent : parent,
					menu : menu,
					link : link,
					task : task
				},success : function(msg){
					var result = eval(msg);
					switch(result){
						case 1:
							$('#mainpanelcontent').empty();
							$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
							$('#mainpanelcontent').load('index.php/c_menu/menu_load');
							alert("Data berhasil disimpan");
							break;
						default:
							alert("Data gagal disimpan");
							break;
					}
				}
			});
		});

		<?php
			if(isset($dataDetail)){
		?>
			menupost_id.val('<?php echo $dataDetail->id; ?>');
			menupost_menu.val('<?php echo $dataDetail->menu; ?>');
			menupost_link.val('<?php echo $dataDetail->link; ?>');
			menupost_task.val('update');
		<?php
			}
		?>

	});

</script>
<!-- Begin content -->
<div class="modal_header">
		<span>Menu Form</span>
	</div>
<div class="modal_content">
<div id="menuadd_content">
	<form action="" method="post" >
		<input type="hidden" id="menupost_id">
		<input type="hidden" id="menupost_task">
		<p>
			<label>Menu:</label><br/>
			<input type="text" id="menupost_menu" class="field_input" style="width:300px"/>
		</p>
		<br/>
		<p>
			<label>Parent:</label><br/>
			<div id="menupost_parent" ></div>
		</p>
		<br/>
		<p>
			<label>Link:</label><br/>
			<input type="text" id="menupost_link" class="field_input"  style="width:300px"/>
		</p>
		<br/>
		<p>
			<table align="left">
				<tr align="left">
					<td>
						<div id='menuadd_save'>
						<img style='float: left; margin: 0px;' src='./images/icons/save.gif' />
						<div style='float: left; margin-left: 4px;'>Simpan</div>
					</div>
					</td>
					<td>
						<div id='menuadd_cancel'>
						<img style='float: left; margin: 0px;' src='./images/icons/cross.gif' />
						<div style='float: left; margin-left: 4px;'>Cancel</div>
					</div>
					</td>
				</tr>
			</table>
		</p>
		<p>&nbsp;</p>
	</form>
</div>
</div>